package com.longwang.controller;

import com.longwang.common.Result;
import com.longwang.entity.Message;
import com.longwang.service.IMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * 前台 -- 留言控制器
 * @author longwang
 * @create 2018-10-25 17:52
 */
@Controller
@RequestMapping("/message")
public class MessageController {

    @Autowired
    private IMessageService iMessageService;

    /**
     * 内容页
     * @return
     */
    @RequestMapping("/index")
    public String index(){
        return "message/index";
    }

    @RequestMapping("/save")
    @ResponseBody
    public Map<String, Object> save(Message message){
        Map<String, Object> resultMap = new HashMap<>();
        message.setId(null);
        Result<String> save = iMessageService.save(message);
        resultMap.put("code", save.getStatus());
        resultMap.put("msg", save.getMsg());
        return resultMap;
    }

}
